package com.twang.stock.controller;

import com.google.common.collect.Lists;
import com.twang.stock.common.http.HtmlTools;
import com.twang.stock.dto.TenXunStock;
import com.twang.stock.dto.ZdtData;
import com.twang.stock.email.SendmailService;
import com.twang.stock.entity.CompanyStockMinutes;
import com.twang.stock.rocketMq.RocketMQProducer;
import com.twang.stock.service.MinutesChengJIaoeService;
import com.twang.stock.service.MinutesStockFixService;
import com.twang.stock.service.NotifyStockBuyService;
import com.twang.stock.service.ZuoTiService;
import com.twang.stock.strategy.WarnVipNewsService;
import com.twang.stock.weixin.WxMessagesManager;
import com.twang.stock.zq.ZhaiQuanServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private WxMessagesManager wxMessagesManager;

    @Autowired
    private RocketMQProducer rocketMQProducer;
    @Autowired
    private NotifyStockBuyService notifyStockBuyService;
    //@Autowired
    //private CompanyStockMinutesRepository companyStockMinutesRepository;

    @Autowired
    private MinutesStockFixService minutesStockFixService;

    @Autowired
    private   SendmailService sendmailService;

    @Autowired
    private ZhaiQuanServcie zhaiQuanServcie;

    @Autowired
    private WarnVipNewsService warnVipNewsService;

    @Autowired
    private ZuoTiService zuoTiService;

    @RequestMapping("/testmq/")
    public String queryZuoTiStatus(){
        rocketMQProducer.sendOneWay("----->>>test---->>>");
        return "SUCCESS";
    }


    @RequestMapping("/minutesChengJIaoeService")
    public String minutesChengJIaoeService(){
        return "SUCCESS";
    }


    @RequestMapping("/zhaiQuanServcie")
    public String zhaiQuanServcie() throws InterruptedException {
        zhaiQuanServcie.getzhuanzhaiList("20240522","1500");
        return "SUCCESS";
    }

    @RequestMapping("/testemail/")
    public String testemail(){
        sendmailService.sendMailWithEmail("1111", "emailMessage.getName()", "emailMessage.getName()", Long.valueOf(1));
        return "SUCCESS";
    }

    @RequestMapping("/warnVipNewsService/")
    public String warnVipNewsService() throws Exception {
        warnVipNewsService.process();
        return "SUCCESS";
    }

    @RequestMapping("/zuoTi/")
    public String zuoTi() throws Exception {
        zuoTiService.做T预警();
        return "SUCCESS";
    }





    @RequestMapping("/wxMessagesManager/")
    public String wxMessagesManager(){
        ZdtData zdtData = new ZdtData();
        zdtData.setZhangTingNum(50);
        zdtData.setDieTingNum(10);
        ZdtData old = new ZdtData();
        old.setZhangTingNum(60);
        old.setDieTingNum(11);
        wxMessagesManager.sendOrderMsg(zdtData,old);
        return "SUCCESS";
    }

    @RequestMapping("/borthMoneyWarn/")
    public String borthMoneyWarn(){
        notifyStockBuyService.borthMoneyWarn(new BigDecimal(-64.49));
        return "SUCCESS";
    }

    @RequestMapping("/httpTenXun/")
    public String httpTenXun(){
        List<String> dataList = HtmlTools.httpTenXun("sz000628");
        List<TenXunStock> tenXunStocks = HtmlTools.httpGet("sz000938");
        return "SUCCESS";
    }

    @RequestMapping("/insertEs/")
    public String insertEs() {
        List<CompanyStockMinutes> insert = Lists.newArrayList();

        minutesStockFixService.getZDT(insert, "sz000938", "紫光股份", "20240520");
       // companyStockMinutesRepository.saveAll(insert);

//        insert.stream().forEach(item->{
//            companyStockMinutesRepository.save(item);
//        });
        CompanyStockMinutes companyStockMinutes = new CompanyStockMinutes();
        companyStockMinutes.setCompanyName("紫光股份");
        companyStockMinutes.setCompanyCode("sz000938");
//        QueryBuilder queryBuilder = QueryBuilders.termQuery("companyName" + ".keyword", "紫光股份");

        //按条件精确查找
//        QueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().must(queryBuilder)
//                .must(QueryBuilders.termQuery("minutes" + ".keyword", "1000"));
        //范围查找
//        boolQueryBuilder = QueryBuilders.boolQuery().must(queryBuilder)
//                .must(QueryBuilders.rangeQuery("vol").gte(2000));

       // Iterable<CompanyStockMinutes> search = companyStockMinutesRepository.search(boolQueryBuilder);

        return "SUCCESS";
    }
}
